package com.yanboot.iot.utils.gb26875.properties;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author fdj
 * @Date 2024/10/26 14:12
 * @Description 消息类处理工厂
 */
public class MessageFactory {

    private static final Map<Integer, Class<? extends Message>> typeToClassMap = new HashMap<>(8);

    static {
        typeToClassMap.put(1, Message1.class);
        typeToClassMap.put(2, Message2.class);
        typeToClassMap.put(3, Message3.class);
        typeToClassMap.put(4, Message4.class);
        typeToClassMap.put(5, Message5.class);
        typeToClassMap.put(6, Message6.class);
        typeToClassMap.put(7, Message7.class);
    }

    /**
     * 根据类型id返回对应报文类型
     *
     * @param type 类型id
     * @return Message Class
     */
    public static Class<? extends Message> getClassByType(int type) {
        Class<? extends Message> messageClass = typeToClassMap.get(type);
        if (messageClass == null) {
            throw new IllegalArgumentException("无效的信息类型: " + type);
        }
        return messageClass;
    }
}
